<template>
  <div class="box">
    <el-button type="primary" @click="getReq">get请求</el-button>
    <el-button type="success" @click="postReq">post请求</el-button>
  </div>
</template>

<script>
// 导入接口层方法
import {apiGet,apiPost} from "@/api/user";

export default {
  name: "App",
  components: {},

  // 封装请求工具优化后↓↓↓
  methods: {
    // 发送get请求
    async getReq() {
      const res = await apiGet(true);
      console.log(res);
      this.$message.success(res.message);
    },

    // 发送post请求
    async postReq() {
      const res = await apiPost({ p1: "参数1", p2: "参数2" }, true);
      console.log(res);
      this.$message.success(res.message);
    },
  },
};
</script>

<style>
.box {
  margin: 100px 500px;
}
</style>
